#pragma once
#include "PThread.hpp" 
#include <iostream>
#include <pthread.h>

#include <vector>

using namespace threadNs;

template<class T>
class RdMutex
{
private:
    static void* handlerTask(void* args)
    {



    }
public:
    RdMutex()
    {
        pthread_rwlock_init(&_rwmutex,nullptr);
        pthread_spin_init(&_spin,nullptr);
        pthread_mutex_init(&_spin,nullptr);
        pthread_cond_init(&_cond,nullptr);
        //创建线程
        for(int i=0;i<_num;i++)
        {
            _task_thread.push_back(new Thread());
        }
    }

    void start()
    {
        for(int i=0;i<_num;i++)
        {
            _task_thread.push_back(new Thread());
        }
    }





    ~RdMutex()
    {
        pthread_rwlock_destroy(&_rwmutex);
        pthread_spin_destroy(&_spin);
        pthread_mutex_destroy(&_spin);
        pthread_cond_destroy(&_cond,nullptr);
    }

private:
    int _num =3;   
    int _rt = 3;
    int _wt = 3;
    std::vector<Thread> _task_thread; //线程
    pthread_rwlock_t _rwmutex;  //读写锁
    pthread_cond_t _cond;       //信号量
    pthread_spinlock_t _spin;   //自旋锁：自旋锁主要是在一直轮询等待，线程一直轮询，自旋锁是一个比较吃场景的锁，不能一直在轮询等待，除非你的线程任务比较少，比较适合这类锁
    pthread_mutex_t _mutex;     //互斥锁：互斥锁主要是挂起等待

};